package com.erpanderp.wam.tm.view;

import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import java.util.TimeZone;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.erpanderp.wam.tm.model.entity.RecruitmentRequest;
import com.erpanderp.wam.tm.model.service.RRFDAO;
import com.erpanderp.wam.usm.model.entity.user.WAMUser;
import com.erpanderp.wam.util.CommonLookup;

@ManagedBean
@ViewScoped
public class ViewRRFByReportingManagerBean implements Serializable {


	private static final long serialVersionUID = 1L;
	private HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
	private HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
	private WAMUser wamUser = (WAMUser) session.getAttribute(CommonLookup.SESSION_ATTRIBUTE_WAMUSER);	
	private TimeZone timeZone = TimeZone.getDefault();
	
	private String employeeId;
	private String rrfCode;
	private String recruiterId;

	private boolean renderUploadButton; 
	private boolean renderBackButton; 
	private boolean renderCloseButton; 
	
	private RRFDAO rrfDAO = new RRFDAO();
	private RecruitmentRequest recruitmentRequest = new RecruitmentRequest();

	public ViewRRFByReportingManagerBean() {		
		
		if(wamUser != null){
			renderBackButton=true;
		}else{
			renderUploadButton=true;			
			renderCloseButton=true;
		}
		
		employeeId = request.getParameter("EMPID");
		rrfCode = request.getParameter("rrfCode");
		recruiterId = request.getParameter("recruiterId");	
		System.out.println("RRF COD EBEAN :::::::"+rrfCode);
		recruitmentRequest = rrfDAO.getRRFByRecruitmentRequestCode(rrfCode);
	}
	public String editAction() throws IOException {
		 
		  Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		  
		  String rrfCode = params.get("rrfCode");
		  String technology = params.get("technology");
		  
		  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("rrfCode", rrfCode);
		  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("technology", technology);
		  
		  FacesContext.getCurrentInstance().getExternalContext().redirect("/wam/tm/uploadResources.html?rrfCode="+rrfCode+"&technology="+technology);
		  
		  System.out.println("rrfCode ==" + FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("rrfCode"));
		  System.out.println("technology==" + FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("technology"));
		  
		  return "uploadresumes";
	 
		}

	//SETTER AND GETTER METHODS
	public String getEmployeeId() {
		return employeeId;
	}

	public void setEmployeeId(String employeeId) {
		this.employeeId = employeeId;
	}

	public String getRecruiterId() {
		return recruiterId;
	}

	public void setRecruiterId(String recruiterId) {
		this.recruiterId = recruiterId;
	}

	public String getRrfCode() {
		return rrfCode;
	}

	public void setRrfCode(String rrfCode) {
		this.rrfCode = rrfCode;
	}

	public RecruitmentRequest getRecruitmentRequest() {
		return recruitmentRequest;
	}

	public void setRecruitmentRequest(RecruitmentRequest recruitmentRequest) {
		this.recruitmentRequest = recruitmentRequest;
	}
	public WAMUser getWamUser() {
		return wamUser;
	}
	public void setWamUser(WAMUser wamUser) {
		this.wamUser = wamUser;
	}
	public boolean isRenderUploadButton() {
		return renderUploadButton;
	}
	public void setRenderUploadButton(boolean renderUploadButton) {
		this.renderUploadButton = renderUploadButton;
	}
	public boolean isRenderBackButton() {
		return renderBackButton;
	}
	public void setRenderBackButton(boolean renderBackButton) {
		this.renderBackButton = renderBackButton;
	}
	public boolean isRenderCloseButton() {
		return renderCloseButton;
	}
	public void setRenderCloseButton(boolean renderCloseButton) {
		this.renderCloseButton = renderCloseButton;
	}
	public TimeZone getTimeZone() {
		return timeZone;
	}
	public void setTimeZone(TimeZone timeZone) {
		this.timeZone = timeZone;
	}

}
